package cn.qyd.javastring;

/**
 * @author 邱运铎
 * @date 2024-03-09 11:45
 */
public class StringInternDemo {
    public static void main(String[] args) {
        String str1 = new String("邱运铎");
        String str2 = "邱运铎";
        System.out.println(str1 == str2);

        String str3 = new String("程序员");
        str3.intern();
        String str4 = "程序员";
        System.out.println(str3 == str4);

        String str5 = new String("Hello") + new String("World");
        str5.intern();
        String str6 = "HelloWorld";
        System.out.println(str5 == str6);

        String str51 = new String("Hello") + new String("World");
        String str61 = "HelloWorld";
        System.out.println(str51 == str61);

        String s7 = new String("StringIntern");
        String s8 = s7.intern();
        System.out.println(s7 == s8);
        String s9 = "StringIntern";
        System.out.println(s8 == s9);
        System.out.println(s7.hashCode()+"---" + s8.hashCode() + "-----" + s9.hashCode()) ;
        System.out.println(System.identityHashCode(s7)+"---" + System.identityHashCode(s8) + "-----" + System.identityHashCode(s9)) ;
    }
}
